<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/table.css"/>
    <script type="text/javascript" src="/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="/js/global-config.js"></script>
    <title>编辑hbase表名</title>
</head>
<body style="margin: 15px;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>编辑hbase表名(<label class="layui-required-tip">标红的为必填项</label>)</legend>
</fieldset>
<form class="layui-form" id="layui-form" action="/manage/data/editTableName" method="post">
    <div class="layui-form-item" style="display: none">
        <label class="layui-form-label layui-required-tip">ID：</label>
        <div class="layui-input-block">
            <input type="text" id="id" name="id" lay-verify="required" autocomplete="off" class="layui-input" value="${tableName.id!}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-required-tip">中文表名：</label>
        <div class="layui-input-block">
            <input type="text" id="tableNameCn" name="tableNameCn" lay-verify="required" value="${tableName.tableNameCn!}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-required-tip">英文表名：</label>
        <div class="layui-input-block">
            <input type="text" id="tableNameEn" name="tableNameEn" lay-verify="required" value="${tableName.tableNameEn!}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" style="display: none;">
        <label class="layui-form-label">rowKey提示汇总：</label>
        <div class="layui-input-block">
            <textarea id="rowkeyHint" name="rowkeyHint" class="layui-textarea">${tableName.rowkeyHint!}</textarea>
        </div>
    </div>
    <div class="layui-form-item layui-inline rowkeyHint">
        <label class="layui-form-label layui-required-tip">rowKey：</label>
        <div class="layui-input-inline">
            <input type="text" placeholder="rowKey提示" autocomplete="off" lay-verify="required" onkeyup="eventRowKeyMsg();" class="layui-input clue1">
        </div>
        <div class="layui-input-inline">
            <input type="text" placeholder="rowKey说明" autocomplete="off" lay-verify="required" onkeyup="eventRowKeyMsg();" class="layui-input explain1">
        </div>
        <div class="layui-input-inline">
            <a class="layui-btn layui-btn-normal" id="addKey"><i class="layui-icon">&#xe654;</i></a>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="save">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary" id="reset" >重置</button>
            <a href="javascript:history.back(-1);" class="layui-btn">返回</a>
        </div>
    </div>
</form>
</div>
<script>
    layui.use(['jquery','form'],function(){
        var $=layui.jquery,form = layui.form,$layer = $('#layui-form'),i=2,x;

        //rowKey提示
        $("#addKey").on("click",function () {
            if(i > 10){
                layer.msg("最多添加10组",{icon:7, shift: 6 });
                return;
            }
            $("form .rowkeyHint:last").after(
                '<div class="layui-form-item layui-inline rowkeyHint"><label class="layui-form-label"></label>'+
                '<div class="layui-input-inline">'+
                '<input type="text" placeholder="请输入rowKey提示" autocomplete="off" lay-verify="required" onkeyup="eventRowKeyMsg();" class="layui-input clue'+i+'">'+
                '</div><div class="layui-input-inline">'+
                '<input type="text" placeholder="rowKey说明" autocomplete="off" lay-verify="required" onkeyup="eventRowKeyMsg();" class="layui-input explain'+i+'">'+
                '</div><div class="layui-input-inline">'+
                '<a class="layui-btn layui-btn-normal" onclick="deleRowKeyMsg(this)"><i class="layui-icon" style="font-size: 17px">&#x1006;</i></a>'+
                '</div></div>'
            );
            i++;
        });

        //填入rowkey
        rowkeyVal();
        function rowkeyVal() {
            var rowkeyHint = $("#rowkeyHint").val();
            if(rowkeyHint){
                var rowkeys =JSON.parse(rowkeyHint);
                for(var s = 0; s < rowkeys.length;s++){
                    if(s > 0){
                        $("#addKey").click();
                    }
                    var item = rowkeys[s];
                    for(var key in item){
                        var msg = key;
                        key = "."+key;
                        $(".rowkeyHint "+key+"").val(item[msg]);
                    }
                }
            }
        }

        //rowkey值合并
        function rowKeyMsg(){
            var rowKeys = {};
            var arr = [];
            for(x=1;x <= i-1;x++){
                var rowkey=$(".rowkeyHint .clue"+x+"").val();
                var explain=$(".rowkeyHint .explain"+x+"").val();

                if('' != rowkey){
                    rowKeys["clue"+x+""] = rowkey;
                }
                if(''!=explain){
                    rowKeys["explain"+x+""] = explain;
                }
                arr.push(rowKeys);
                rowKeys = {};
            }
            return JSON.stringify(arr);
        }

        window.eventRowKeyMsg=function(){
            $("#rowkeyHint").val(rowKeyMsg());
        }

        //删除input组
        window.deleRowKeyMsg = function(that) {
            that.parentNode.parentNode.remove();
            i--;
            eventRowKeyMsg();
        }

        //监听提交监听提交
        form.on('submit(save)', function(data){
            layer.confirm('确认要提交吗？', {
                btn : [ '确定', '取消' ]//按钮
            }, function(index) {
                $layer.submit();
                layer.close(index);
            });
            return false;
        });
    });
</script>
</body>
</html>